import Vue from 'vue';
import Vuex from 'vuex';
import {getStorage,setStorage,removeStorage} from '@/util/storage'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        user:{
            userid:null,
            username:"",
            usernickname:"",
            userrole:""
        },
        authorization:""
    },
    getters:{
        getuser(state){
            let user = getStorage('user');
            state.user  = user;
            return state.user;
        },

    },
    mutations: {
        setuser(state,obj){
            // state.user.userid = obj.userid || state.user.userid;
            // state.user.username = obj.username || state.user.username;
            // state.user.usernickname = obj.usernickname || state.user.usernickname;
            // state.user.userrole = obj.username.userrole || state.user.userrole;
            state.user = obj
            setStorage('user',obj);
        },
        removeuser(state){
            state.user = {
                userid:null,
                username:"",
                usernickname:"",
                userrole:""
            };
            removeStorage('user');
        }
    },
    actions:{

    }



});

export default store;
